#!/usr/bin/env python
# coding=utf-8
"""
查询nest中操作的日志
"""
import json

from flask import Blueprint, session, jsonify

from mynest.service.logsv import LogSV

nest = Blueprint('log', __name__)


@nest.route('/logs', methods=['GET'])
def logList():
    if 'token' in session:
        """
        查询日志分组集合
        """
        logSV = LogSV()
        logs = logSV.listLogs()
        return jsonify(logs)
    else:
        return jsonify({"code": "00000", "success": False, "info": "查询日志不存在"})


@nest.route('/logs/<job>', methods=['GET'])
def logListByJob(job):
    """
    根据job类型查询列表日志
    :param job:Auth,Lock,DoorLight,BedLight,RoomLight
    :return:list
    """
    if 'token' in session:
        logSV = LogSV()
        logs = logSV.listLogsByJob(job)
        return jsonify(logs)
    else:
        return jsonify({"code": "00000", "success": False, "info": "查询日志不存在"})
